package com.leetcode.根据数据结构分类.数组;

/**
 * @author: xiaomi
 * @date: 2021/1/17
 * @description: 5653. 可以形成最大正方形的矩形数目
 * https://leetcode-cn.com/contest/weekly-contest-224/problems/number-of-rectangles-that-can-form-the-largest-square/
 */
public class A_5653_可以形成最大正方形的矩形数目 {

    public int countGoodRectangles(int[][] rectangles) {
        int len = rectangles.length;
        //int[] rec =new int[len];
        int maxLen = 0;
        int count = 0;
        for (int i = 0; i < len; i++) {
            int min = Math.min(rectangles[i][0], rectangles[i][1]);
            if (min == maxLen) {
                count++;
            } else if (min > maxLen) {
                maxLen = min;
                count = 1;
            }
        }
        return count;
    }

    public static void main(String[] args) {
        int[][] rectangles = {{5, 8}, {3, 9}, {5, 12}, {16, 5}};
        A_5653_可以形成最大正方形的矩形数目 action = new A_5653_可以形成最大正方形的矩形数目();
        int res = action.countGoodRectangles(rectangles);
        System.out.println("res = " + res);
    }
}
